<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="telnet-example.html" />
<link rel="prev" href="module-telnetlib.html" />
<link rel="parent" href="module-telnetlib.html" />
<link rel="next" href="telnet-example.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>18.15.1 Telnet Objects </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="18.15 telnetlib  "
  href="module-telnetlib.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="18.15 telnetlib  "
  href="module-telnetlib.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="18.15.2 telnet Example"
  href="telnet-example.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-telnetlib.html">18.15 telnetlib  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-telnetlib.html">18.15 telnetlib  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="telnet-example.html">18.15.2 Telnet Example</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION00201510000000000000000"></a><a name="telnet-objects"></a>
<br>
18.15.1 Telnet Objects 
</h2>

<p>
<tt class="class">Telnet</tt> instances have the following methods:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4230' xml:id='l2h-4230' class="method">read_until</tt></b>(</nobr></td>
  <td><var>expected</var><big>[</big><var>, timeout</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Read until a given string, <var>expected</var>, is encountered or until
<var>timeout</var> seconds have passed.

<p>
When no match is found, return whatever is available instead,
possibly the empty string.  Raise <tt class="exception">EOFError</tt> if the connection
is closed and no cooked data is available.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4231' xml:id='l2h-4231' class="method">read_all</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Read all data until EOF; block until connection closed.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4232' xml:id='l2h-4232' class="method">read_some</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Read at least one byte of cooked data unless EOF is hit.
Return <code>''</code> if EOF is hit.  Block if no data is immediately
available.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4233' xml:id='l2h-4233' class="method">read_very_eager</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Read everything that can be without blocking in I/O (eager).

<p>
Raise <tt class="exception">EOFError</tt> if connection closed and no cooked data
available.  Return <code>''</code> if no cooked data available otherwise.
Do not block unless in the midst of an IAC sequence.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4234' xml:id='l2h-4234' class="method">read_eager</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Read readily available data.

<p>
Raise <tt class="exception">EOFError</tt> if connection closed and no cooked data
available.  Return <code>''</code> if no cooked data available otherwise.
Do not block unless in the midst of an IAC sequence.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4235' xml:id='l2h-4235' class="method">read_lazy</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Process and return data already in the queues (lazy).

<p>
Raise <tt class="exception">EOFError</tt> if connection closed and no data available.
Return <code>''</code> if no cooked data available otherwise.  Do not block
unless in the midst of an IAC sequence.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4236' xml:id='l2h-4236' class="method">read_very_lazy</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return any data available in the cooked queue (very lazy).

<p>
Raise <tt class="exception">EOFError</tt> if connection closed and no data available.
Return <code>''</code> if no cooked data available otherwise.  This method
never blocks.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4237' xml:id='l2h-4237' class="method">read_sb_data</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return the data collected between a SB/SE pair (suboption begin/end).
The callback should access these data when it was invoked with a
<code>SE</code> command. This method never blocks.

<p>

<span class="versionnote">New in version 2.3.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4238' xml:id='l2h-4238' class="method">open</tt></b>(</nobr></td>
  <td><var>host</var><big>[</big><var>, port</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Connect to a host.
The optional second argument is the port number, which
defaults to the standard Telnet port (23).

<p>
Do not try to reopen an already connected instance.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4239' xml:id='l2h-4239' class="method">msg</tt></b>(</nobr></td>
  <td><var>msg</var><big>[</big><var>, *args</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Print a debug message when the debug level is <code>&gt;</code> 0.
If extra arguments are present, they are substituted in the
message using the standard string formatting operator.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4240' xml:id='l2h-4240' class="method">set_debuglevel</tt></b>(</nobr></td>
  <td><var>debuglevel</var>)</td></tr></table></dt>
<dd>
Set the debug level.  The higher the value of <var>debuglevel</var>, the
more debug output you get (on <code>sys.stdout</code>).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4241' xml:id='l2h-4241' class="method">close</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Close the connection.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4242' xml:id='l2h-4242' class="method">get_socket</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return the socket object used internally.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4243' xml:id='l2h-4243' class="method">fileno</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return the file descriptor of the socket object used internally.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4244' xml:id='l2h-4244' class="method">write</tt></b>(</nobr></td>
  <td><var>buffer</var>)</td></tr></table></dt>
<dd>
Write a string to the socket, doubling any IAC characters.
This can block if the connection is blocked.  May raise
<tt class="exception">socket.error</tt> if the connection is closed.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4245' xml:id='l2h-4245' class="method">interact</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Interaction function, emulates a very dumb Telnet client.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4246' xml:id='l2h-4246' class="method">mt_interact</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Multithreaded version of <tt class="method">interact()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4247' xml:id='l2h-4247' class="method">expect</tt></b>(</nobr></td>
  <td><var>list</var><big>[</big><var>, timeout</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Read until one from a list of a regular expressions matches.

<p>
The first argument is a list of regular expressions, either
compiled (<tt class="class">re.RegexObject</tt> instances) or uncompiled (strings).
The optional second argument is a timeout, in seconds; the default
is to block indefinitely.

<p>
Return a tuple of three items: the index in the list of the
first regular expression that matches; the match object
returned; and the text read up till and including the match.

<p>
If end of file is found and no text was read, raise
<tt class="exception">EOFError</tt>.  Otherwise, when nothing matches, return
<code>(-1, None, <var>text</var>)</code> where <var>text</var> is the text received so
far (may be the empty string if a timeout happened).

<p>
If a regular expression ends with a greedy match (such as <tt class="regexp">.*</tt>)
or if more than one expression can match the same input, the
results are indeterministic, and may depend on the I/O timing.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4248' xml:id='l2h-4248' class="method">set_option_negotiation_callback</tt></b>(</nobr></td>
  <td><var>callback</var>)</td></tr></table></dt>
<dd>
Each time a telnet option is read on the input flow, this
<var>callback</var> (if set) is called with the following parameters :
callback(telnet socket, command (DO/DONT/WILL/WONT), option).  No other
action is done afterwards by telnetlib.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="18.15 telnetlib  "
  href="module-telnetlib.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="18.15 telnetlib  "
  href="module-telnetlib.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="18.15.2 telnet Example"
  href="telnet-example.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-telnetlib.html">18.15 telnetlib  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-telnetlib.html">18.15 telnetlib  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="telnet-example.html">18.15.2 Telnet Example</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
